<template>
  <div class="goods-relevant">
    <div class="header">
      <i class="icon"  />
      <span class="title">{{ goodsId ? "同类商品推荐" : "猜你喜欢" }}</span>
    </div>
    <!-- 此处使用改造后的xtx-carousel.vue -->
    <XtxCarousel :tong="tong"></XtxCarousel>
  </div>
</template>
  
<script>
import {findRelGoods} from '@/utils/api/detail'
import XtxCarousel from "./XtxCarousel.vue";
export default {
  // 同类推荐，猜你喜欢
  name: 'GoodsRelevant',
  components: { XtxCarousel },
  props: ["goodsId"],
  data() {
    return {
      slides: [],
      list: {
        name: null,
        price: null,
        picture: null,
      },
    };
  },
  methods: {
    async lists() {
      let res = await findRelGoods(this.goodsId);
      this.slides = res.result;
      // console.log(this.slides);
    },
  },
  mounted() {
    this.lists();
  },
  computed: {
    tong() {
      var arr = []
      this.slides.forEach((item) => {
        this.list.name = item.name;
        this.list.picture = item.picture;
        this.list.price = item.price;
        arr.push({ ...this.list })
      });
      return arr
    },
  },
}
</script>
  
  <style scoped lang='scss'>
  @import '@/assets/css/variables.scss';
  .goods-relevant {
    background: #fff;
    min-height: 460px;
    margin-top: 20px;
    .header {
      height: 80px;
      line-height: 80px;
      padding: 0 20px;
      .title {
        font-size: 20px;
        padding-left: 10px;
      }
      .icon {
        width: 16px;
        height: 16px;
        display: inline-block;
        border-top: 4px solid $xtxColor;
        border-right: 4px solid $xtxColor;
        box-sizing: border-box;
        position: relative;
        transform: rotate(45deg);
        &::before {
          content: "";
          width: 10px;
          height: 10px;
          position: absolute;
          left: 0;
          top: 2px;
          background: lighten($xtxColor, 40%);
        }
      }
    }
    ul{
      display: flex;
      justify-content: space-around;
      flex-wrap: wrap;
      li{
        width: 20%;
        text-align: center;
      }
    }
  }
  </style>